using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class DigRow {
	public TileData tile;
	public TileData tileEnd;
	public Vector2Int offset;
	public Vector2Int direction;
	public void Dig(Vector2Int objectPosition,bool rotate) {
		Vector2Int offset = this.offset;
		Vector2Int direction = this.direction;
		if(rotate) {
			int tmp = offset.x;
			offset.x=offset.y;
			offset.y=tmp;
			tmp =direction.x;
			direction.x=direction.y;
			direction.y=tmp;
		}

		Vector2Int pos = objectPosition+offset;

		for(int _ = 0;_<32;_++) {
			pos+=direction;
			if(!TilemapController.SolidAt(pos)) break;
			TilemapController.SetTile(pos,tile);
		}
		pos-=direction;
		TilemapController.SetTile(pos,tileEnd);
	}
}

public class WangTileRecorderDigger:WangTileRecorder {

	[SerializeField] DigRow[] digRows;

	public override void SetTiles(bool flipX,bool flipY,bool rotate) {
		base.SetTiles(flipX,flipY,rotate);

		Vector2Int selfPosition = new Vector2Int((int)transform.position.x,(int)transform.position.y);
		foreach(var row in digRows) row.Dig(selfPosition,rotate);

	}

}
